<?php
function news_random($category, $chars, $template, $count=10) {
	global $conf, $lang;

	SQLvalidate($category);
	SQLvalidate($count);
	if($category) $cat='and cat='.$category;
	
	$db = new dbquery;
	$db->query("SELECT * FROM $conf[prefix]news WHERE visible=1 $cat and text_$_SESSION[lang_short] != '' ORDER BY RAND() LIMIT $count") or $db->err(__FILE__, __LINE__);

	$list = null;

	while($new = $db->fetch_object()) {
		$tl='title_'.$_SESSION['lang_short'];
		$t='text_'.$_SESSION['lang_short'];

		if($new->$tl==''){
			$tl='title_'.$conf['language'];
			$t='text_'.$conf['language'];
		}

		$title = read_text_rest($new->$tl);
		$text = strip_exbcode(add_dots_($new->$t, 200));

		if($conf['mod_rewrite']) //jezeli wlaczony mod_rewrite
		$url='new-'.read_text_mr($new->$tl).'_'.$new->id.'.html';
		else
		$url='index.php?module=article&amp;id='.$new->id;

		$overLIB=string_template($lang['article_overlib'], array('theme_path'=>$GLOBALS['theme_path'], 'title'=>$title, 'text'=>$text, 'rating'=>$new->rating, 'votes'=>$new->votes));
		$overLIB=overlib_text($overLIB);
		$overLIB=" onmouseover=\"return overlib('$overLIB');\" onmouseout=\"return nd();\" ";

		$title=substr($title, 0,$chars);
		$list .= string_template($template, array('url' => $url, 'id' => $new->id, 'name' => $title, 'date' => date($conf['date_format'], strtotime($new->date)), 'author' => get_user_link_by_id($new->author), 'read' => $new->viewed, 'overlib' => $overLIB));
	}
	echo($list);
}
?>
